package org.apache.solr.client;

import java.util.ArrayList;
import java.util.List;

public class FieldFacet 
{
	public static class Count 
	{
		private String _name = null;
		private int _count = 0;
		
		public Count( String n, int c )
		{
			_name = n;
			_count = c;
		}
		
		public String getName() {
			return _name;
		}

		public int getCount() {
			return _count;
		}
		
		public String toString()
		{
			return _name+" ("+_count+")";
		}
	}
	
	private String      _name   = null;
	private List<Count> _values = null;
	
	public FieldFacet( final String n )
	{
		_name = n;
	}
	
	public void add( String name, int cnt )
	{
		if( _values == null ) {
			_values = new ArrayList<Count>( 30 );
		}
		_values.add( new Count( name, cnt ) );
	}

	public String getName() {
		return _name;
	}

	public List<Count> getValues() {
		return _values;
	}
	
	public int getValueCount()
	{
		return _values == null ? 0 : _values.size();
	}

	public FieldFacet getLimitingFields(int max) 
	{
		FieldFacet ff = new FieldFacet( _name );
		if( _values != null ) {
			ff._values = new ArrayList<Count>( _values.size() );
			for( Count c : _values ) {
				if( c._count < max ) { // !equal to
					ff._values.add( c );
				}
			}
		}
		return ff;
	}
	
	public String toString()
	{
		return _name + ":" + _values;
	}
}
